import { Component } from '@angular/core';
import { IonicPage, NavController } from 'ionic-angular';
import { ConfigProvider } from '../../providers/config/config';

import { Http, Jsonp } from "@angular/http";
import { HttpServicesProvider } from '../../providers/http-services/http-services';

@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  public focusList = []
  public bestList = []
  public bestListWidth: string = ''

  public hotList = []
  constructor(
    public navCtrl: NavController,
    public config: ConfigProvider,
    public jsonp: Jsonp,
    public http: Http,
    public httpServices: HttpServicesProvider
  ) {
    // 调用轮播图
    this.getFocus()
    // 调用精品推荐
    this.getBestProduct()
    // 猜你喜欢
    this.getHotProduct()
  }

  // 跳转到搜索页面
  goSearch() {
    this.navCtrl.push('SearchPage')
  }

  // 轮播图
  getFocus() {
    this.httpServices.requestData('api/focus', res => {
      this.focusList = res.result
    })
  }

  // 精品推荐数据
  getBestProduct() {
    this.httpServices.requestData('api/plist?is_best=1', res => {
      this.bestList = res.result
      this.bestListWidth = this.bestList.length * 80+ 'px'
    })
  }

  // 猜你喜欢
  getHotProduct() {
    this.httpServices.requestData('api/plist?is_hot=1', res => {
      this.hotList = res.result
    })
  }

}
